package com.work.yshop.utils;

import com.work.yshop.mvp.contract.LoginContract;

/**
 * 用户会话管理类，单例模式
 */
public class UserSession {
    private static UserSession instance;
    
    // 用户类型：1-买家，2-卖家
    private int userType = LoginContract.USER_TYPE_BUYER;
    
    // 用户ID
    private int userId = 1;
    
    // 用户名
    private String username = "用户";
    
    // 是否已登录
    private boolean isLoggedIn = false;
    
    private UserSession() {
        // 私有构造方法
    }
    
    public static synchronized UserSession getInstance() {
        if (instance == null) {
            instance = new UserSession();
        }
        return instance;
    }
    
    public int getUserType() {
        return userType;
    }
    
    public void setUserType(int userType) {
        this.userType = userType;
        this.isLoggedIn = true;
    }
    
    public int getUserId() {
        return userId;
    }
    
    public void setUserId(int userId) {
        this.userId = userId;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public boolean isLoggedIn() {
        return isLoggedIn;
    }
    
    public void setLoggedIn(boolean loggedIn) {
        isLoggedIn = loggedIn;
    }
    
    public boolean isBuyer() {
        return userType == LoginContract.USER_TYPE_BUYER;
    }
    
    public boolean isSeller() {
        return userType == LoginContract.USER_TYPE_SELLER;
    }
    
    /**
     * 清除会话信息
     */
    public void clear() {
        userType = LoginContract.USER_TYPE_BUYER;
        userId = 0;
        username = "";
        isLoggedIn = false;
    }
} 